package com.study.test;

import com.csvreader.CsvWriter;

import java.io.*;
import java.nio.charset.Charset;

public class ZipOutputStreamDemo {

    public static void test(String file) {
        CsvWriter csvWriter = new CsvWriter(file, ',', Charset.forName("UTF-8"));
        // 设置标题
        String[] title = {"PI", "\"type\", \"subtype\", \"rcsSubType\", \"propertyId\"," +
                "\"propertyName\", \"currValue\", \"validFrom\",\"validFromWithTime\"," +
                " \"validTo\", \"validToWithTime\""};
        try {
            csvWriter.writeRecord(title);
            // 写入内容
            String[] csvContent1 = { "\"201804\"", "\"小鱼\"" };
            csvWriter.writeRecord(csvContent1);
            String[] csvContent2 = { "201805", "小fds" };
            csvWriter.writeRecord(csvContent2);
            csvWriter.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) throws IOException {

//        String fileName = "D://Test.csv";
//        test(fileName);

        String line = "\"110022001\"";
        Long pi = 110022001L;
        System.out.println(line.replace("\"",""));
        System.out.println(pi.toString().equals(line.replace("\"","")));

//        FileOutputStream fOutputStream = null;
//        ZipOutputStream zoutput = null;
//        ZipEntry zEntry = null;
//        String zip_fileName = "D:\\" + "Demo.zip";
//        String fileName = "Demo.csv";
//
//        File file = new File(zip_fileName);
//        File file1 = new File(fileName);
//        fOutputStream = new FileOutputStream(file);
//        FileOutputStream fOutputStream1 = new FileOutputStream(file1,true);
//        BufferedWriter out = new BufferedWriter(new OutputStreamWriter(fOutputStream1, "UTF-8"));
//        String title = "\"PI\", \"type\", \"subtype\", \"rcsSubType\", \"propertyId\"," +
//                "\"propertyName\", \"currValue\", \"validFrom\",\"validFromWithTime\"," +
//                " \"validTo\", \"validToWithTime\"";
//        out.write(title);
//        out.newLine();
//        out.flush();
//
//        zoutput = new ZipOutputStream(fOutputStream);
//        zEntry  = new ZipEntry(fileName);
//        zoutput.putNextEntry(zEntry);
//        //zoutput.write(title.getBytes());
//        zoutput.flush();
//        zoutput.close();
    }
//        String filePath = "D:\\Warrants\\mynaFiles\\PI\\" + "RDC-bodyGroup-PI-20180920.csv";
//        CsvReader reader = null;
//        String[] stringList;
//        try {
//            reader = new CsvReader(filePath);
//            while (reader.readRecord()) {
//                stringList = reader.getValues();
//                //stringList[0] PI value
//                if (stringList[0].equals(110022044)) {
//                    System.out.println("=====================");
//                }
//            }
//        } catch (Exception e) {
//            e.printStackTrace();
//        } finally {
//            if (reader != null) {
//                reader.close();
//            }
//        }


//        File file = new File("D:" + File.separator + "zipOutput.txt");
//        File zipFile = new File("D:" + File.separator + "zipOutput.zip");
//        if (!file.exists()) {
//            file.createNewFile();
//        }
//        if (!zipFile.exists()) {
//            zipFile.createNewFile();
//        }
//        FileInputStream fis = new FileInputStream(file);
//        String str = "您好，祝您开心！";
//        FileOutputStream fos = new FileOutputStream(file);
//        fos.write(str.getBytes());
//        fos.close();
//        ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(zipFile));
//        zos.putNextEntry(new ZipEntry(file.getName()));
//        zos.setComment("测试ZipOutputStream压缩与解压缩！");
//        int temp = 0;
//        while ((temp = fis.read()) != -1) {
//            zos.write(temp);
//        }
//        fis.close();
//        zos.close();
//        String primStr = "{\"pi\":110011005,\"rcs_subtype\":\"FXKNOCKIN\",\"rdcProperties\":[{\"currValue\":\"WRTXXX000001\",\"property_id\":27229,\"validFrom\":\"20180105\",\"validFromWithTime\":\"20180105190000\",\"validTo\":\"20180120\",\"valid_to_inc_time\":\"20180120200000\"},{\"currValue\":\"WRTXXX000019\",\"property_id\":27229,\"validFrom\":\"20180120\",\"validFromWithTime\":\"20180120235959\",\"validTo\":\"20180128\",\"valid_to_inc_time\":\"20180128235959\"},{\"currValue\":\"WRTXXX000027\",\"property_id\":27229,\"validFrom\":\"20180129\",\"validFromWithTime\":\"20180129190000\",\"validTo\":\"20180203\",\"valid_to_inc_time\":\"20180203185959\"},{\"currValue\":\"WRTXXX000035\",\"property_id\":27229,\"validFrom\":\"20180204\",\"validFromWithTime\":\"20180204185959\",\"validTo\":\"20180502\",\"valid_to_inc_time\":\"20180502190000\"},{\"currValue\":\"WRTXXX000043\",\"property_id\":27229,\"validFrom\":\"20180505\",\"validFromWithTime\":\"20180505235959\"}],\"subtype\":\"EIW\",\"type\":\"I\"}";
//        System.out.println(gzip(primStr));
//    }
//
//        public static String gzip (String primStr){
//            if (primStr == null || primStr.length() == 0) {
//                return primStr;
//            }
//
//            ByteArrayOutputStream out = new ByteArrayOutputStream();
//
//            GZIPOutputStream gzip = null;
//            try {
//                gzip = new GZIPOutputStream(out);
//                gzip.write(primStr.getBytes(StandardCharsets.UTF_8));
//            } catch (IOException e) {
//                e.printStackTrace();
//            } finally {
//                if (gzip != null) {
//                    try {
//                        gzip.close();
//                    } catch (IOException e) {
//                        e.printStackTrace();
//                    }
//                }
//            }
//            return new sun.misc.BASE64Encoder().encode(out.toByteArray());
//        }
    }